package com.deepplin.mongodbmanager;

import java.util.List;

import com.deepplin.mongodbmanager.control.MongoDBController;
import com.deepplin.mongodbmanager.form.MongoDBLoginFrm;
import com.deepplin.mongodbmanager.form.MongoDBManagerFrm;

public class MongoDBManager {

	private MongoDBManagerFrm mgFrm = null;
	private MongoDBLoginFrm mgLoginFrm = null;
	
	private MongoDBController mgController = null;
	
	private List<String>listDB = null;
	
	public MongoDBManager(){
		mgFrm = new MongoDBManagerFrm( );	
		mgController = MongoDBController.getInstance();
	}
	
	/**
	 * 
	 */
	private void run(){
		mgFrm.setVisible(true);
		mgFrm.init(this);
		mgFrm.start();
	}
	
	/**
	 * 
	 * @param bCheck
	 */
	public void runLogin( boolean bCheck){
		mgLoginFrm = new MongoDBLoginFrm();
		mgLoginFrm.init(this);
		mgLoginFrm.setVisible(bCheck);
		mgFrm.setEnabled(!bCheck);		
	}	
	
	/**
	 * DB리스트 가져 오기
	 * @param HOST
	 * @param PORT
	 * @return
	 */
	public boolean getDBList( String HOST, String PORT){
		listDB = mgController.getDBList(HOST, PORT);
		if( listDB == null){
			return false;
		}
		else{
			return true;
		}		
	}
	
	/**
	 * 서버 접속 성공 
	 * @param bCheck
	 */
	public void runManager( boolean bCheck){
		mgLoginFrm.setVisible(!bCheck);
		mgFrm.setVisible(bCheck);
		mgFrm.setEnabled(bCheck);
		
		mgFrm.setDBList(listDB);
	}
	
	public static void main( String[] args){
		MongoDBManager mg = new MongoDBManager();
		mg.run();
	}
	
}
